<?php

namespace common\models\trade;

use Yii;

/**
 * This is the model class for table "{{%platform_import_errors}}".
 *
 * @property int $id
 * @property int $batch_id 导入批次id
 * @property string $pay_no 支付平台交易号
 * @property string $trade_no 商户交易号
 * @property string $pay 账单金额
 * @property int $balance 收支类型 1 支付 | -1 退款 
 * @property string $type 批次类型 alipay 支付宝 | wechat 微信
 * @property int $import_time 入账时间
 * @property string $handle_log 处理操作记录
 * @property int $handle_time 处理时间
 * @property int $handle_admin_id 处理操作人id
 * @property int $created_at 创建时间
 */
class PlatFormImportErrors extends \common\db\ActiveRecord
{

    use \common\traits\Constants;

    const EXCEP_SHOPBUY_ONE = "shopbuy_1";
    const EXCEP_SHOPBUY_TWO = "shopbuy_2";
    const EXCEP_SHOPBUY_THREE = "shopbuy_3";
    const EXCEP_SHOPBUY_FOUR = "shopbuy_4";
    const EXCEP_SHOPBUY_FIVE = "shopbuy_5";
    const EXCEP_SHOPBUY_SIX = "shopbuy_6";
    const EXCEP_SHOPBUY_SEVEN = "shopbuy_7";
    const EXCEP_SHOPBUY_EIGHT = "shopbuy_8";

    const EXCEP_SHOPREFUND_ONE = "shoprefund_1";
    const EXCEP_SHOPREFUND_TWO = "shoprefund_2";
    const EXCEP_SHOPREFUND_THREE = "shoprefund_3";
    const EXCEP_SHOPREFUND_FOUR = "shoprefund_4";
    const EXCEP_SHOPREFUND_FIVE = "shoprefund_5";
    const EXCEP_SHOPREFUND_SIX = "shoprefund_6";
    const EXCEP_SHOPREFUND_SEVEN = "shoprefund_7";
    const EXCEP_SHOPREFUND_EIGHT = "shoprefund_8";


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%platform_import_errors}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['batch_id', 'balance', 'import_time', 'handle_time', 'handle_admin_id', 'created_at'], 'integer'],
            [['pay'], 'number'],
            [['handle_log'], 'string'],
            [['pay_no', 'trade_no','order_no','refund_no'], 'string', 'max' => 32],
            [['type','excep_no'], 'string', 'max' => 20],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'batch_id' => 'Batch ID',
            'pay_no' => 'Pay No',
            'trade_no' => 'Trade No',
            'order_no' => '商城订单',
            'pay' => 'Pay',
            'balance' => 'Balance',
            'type' => 'Type',
            'import_time' => 'Import Time',
            'handle_log' => 'Handle Log',
            'handle_time' => 'Handle Time',
            'handle_admin_id' => 'Handle Admin ID',
            'created_at' => 'Created At',
            'refund_no' => '业务退款单号',
        ];
    }

    public static function excepbeasons(){
        return [
            PlatFormImportBatch::TYPE_SHOPBUY =>[
                static::EXCEP_SHOPBUY_ONE => '交易号未更新到业务订单',
                static::EXCEP_SHOPBUY_TWO => '交易号不存在',
                static::EXCEP_SHOPBUY_THREE => '交易支付成功，但业务订单未支付或者取消',
                static::EXCEP_SHOPBUY_FOUR => '交易取消，但业务订单已支付或者后续状态',
                static::EXCEP_SHOPBUY_FIVE => '金额不匹配',
                static::EXCEP_SHOPBUY_SIX => '',
                static::EXCEP_SHOPBUY_SEVEN => '',
                static::EXCEP_SHOPBUY_EIGHT => '',
            ],
            PlatFormImportBatch::TYPE_SHOPREFUND =>[
                static::EXCEP_SHOPREFUND_ONE => '未生成退款交易',
                static::EXCEP_SHOPREFUND_TWO => '业务订单为申请退款',
                static::EXCEP_SHOPREFUND_THREE => '业务订单正在退款中',
                static::EXCEP_SHOPREFUND_FOUR => '支付交易不存在',
                static::EXCEP_SHOPREFUND_FIVE => '退款金额不匹配',
                static::EXCEP_SHOPREFUND_SIX => '',
                static::EXCEP_SHOPREFUND_SEVEN => '',
                static::EXCEP_SHOPREFUND_EIGHT => '',
            ]
        ];
    }
}
